package com.settlement.system.controller;

import com.settlement.system.common.result.Result;
import com.settlement.system.service.SysAuditService;
import com.settlement.system.service.SysBillSummaryService;
import com.settlement.system.service.SysDoneAuditService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 删除系统数据 控制类
 */
@Tag(name = "删除系统数据")
@RestController
@RequestMapping("/api/v1/emptyTable")
@RequiredArgsConstructor
public class SystemDataDeleteController {

    private final SysBillSummaryService sysBillSummaryService;

    private final SysDoneAuditService sysDoneAuditService;

    private final SysAuditService sysAuditService;

    @Operation(summary = "删除系统数据", security = {@SecurityRequirement(name = "Authorization")})
    @GetMapping("/confirm")
    public Result<?> sourceImport(@Parameter(description = "所选月份") String month) {
        // 删除核销单
        sysAuditService.deleteByMonth(month);
        // 删除已办核销单
        sysDoneAuditService.deleteByMonth(month);
        // 删除归档核销单
        String tableName = "sys_file_audit_%s".formatted(month);
        sysBillSummaryService.deleteTable(tableName);
        // 删除标准订单
        tableName = "sys_order_%s".formatted(month);
        sysBillSummaryService.deleteTable(tableName);
        // 删除标准账单
        tableName = "sys_bill_%s".formatted(month);
        sysBillSummaryService.deleteTable(tableName);
        // 删除抖音标准订单
        tableName = "dy_order_%s".formatted(month);
        sysBillSummaryService.deleteTable(tableName);
        // 删除抖音标准账单
        tableName = "dy_bill_%s".formatted(month);
        sysBillSummaryService.deleteTable(tableName);
        // 删除淘宝原始订单
        tableName = "tb_order_%s".formatted(month);
        sysBillSummaryService.deleteTable(tableName);
        // 删除淘宝原始账单
        tableName = "tb_bill_%s".formatted(month);
        sysBillSummaryService.deleteTable(tableName);
        // 删除京东原始订单
        tableName = "jd_order_%s".formatted(month);
        sysBillSummaryService.deleteTable(tableName);
        // 删除京东原始账单
        tableName = "jd_bill_%s".formatted(month);
        sysBillSummaryService.deleteTable(tableName);
        // 删除天猫原始订单
        tableName = "tm_order_%s".formatted(month);
        sysBillSummaryService.deleteTable(tableName);
        // 删除天猫原始账单
        tableName = "tm_bill_%s".formatted(month);
        sysBillSummaryService.deleteTable(tableName);
        // 删除唯品会原始订单
        tableName = "vip_order_%s".formatted(month);
        sysBillSummaryService.deleteTable(tableName);
        // 删除唯品会原始账单
        tableName = "vip_bill_%s".formatted(month);
        sysBillSummaryService.deleteTable(tableName);
        // 删除快手原始订单
        tableName = "ks_order_%s".formatted(month);
        sysBillSummaryService.deleteTable(tableName);
        // 删除快手原始账单
        tableName = "ks_bill_%s".formatted(month);
        sysBillSummaryService.deleteTable(tableName);
        // 删除小红书原始订单
        tableName = "redBook_order_%s".formatted(month);
        sysBillSummaryService.deleteTable(tableName);
        // 删除小红书原始账单
        tableName = "redBook_bill_%s".formatted(month);
        sysBillSummaryService.deleteTable(tableName);
        // 删除视频号原始订单
        tableName = "video_order_%s".formatted(month);
        sysBillSummaryService.deleteTable(tableName);
        // 删除视频号原始账单
        tableName = "video_bill_%s".formatted(month);
        sysBillSummaryService.deleteTable(tableName);
        // 删除拼多多原始订单
        tableName = "pdd_order_%s".formatted(month);
        sysBillSummaryService.deleteTable(tableName);
        // 删除拼多多原始账单
        tableName = "pdd_bill_%s".formatted(month);
        sysBillSummaryService.deleteTable(tableName);
        // 删除有赞原始订单
        tableName = "yz_order_%s".formatted(month);
        sysBillSummaryService.deleteTable(tableName);
        // 删除有赞原始账单
        tableName = "yz_bill_%s".formatted(month);
        sysBillSummaryService.deleteTable(tableName);
        return Result.success("删除成功");
    }

}
